package com.github.base.controller;

import com.github.base.annotation.SysLog;
import com.github.base.domain.Dept;
import com.github.base.dto.dept.DeptAddDTO;
import com.github.base.dto.dept.DeptOrderDTO;
import com.github.base.dto.dept.DeptSearchDTO;
import com.github.base.dto.dept.DeptUpdateDTO;
import com.github.base.service.DeptService;
import com.github.base.utils.Result;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 机构API
 *
 * @author zhouwentong
 * @version v1.0
 * @since v1.0
 * Create by zhouwentong 2021-01-28
 */

@RestController
@RequestMapping("/dept")
@Tag(name = "机构部门")
@AllArgsConstructor
public class DeptController {
    private final DeptService deptService;

    @SysLog(module = "机构模块", value = "新增机构")
    @ApiOperationSupport(order = 1)
    @Operation(summary = "机构添加")
    @PostMapping(value = "/add")
    public Result<?> add(@Validated @RequestBody DeptAddDTO deptAddDTO ) {
        deptService.saveDept(deptAddDTO);
        return Result.ok();
    }


    @ApiOperationSupport(order = 2)
    @Operation(summary = "当前人部门树数据")
    @PostMapping(value = "/current")
    public Result<List<Dept>> current(@Validated @RequestBody DeptSearchDTO deptSearchDTO ) {
        List<Dept> list = deptService.current(deptSearchDTO);
        return Result.ok(list);
    }

    @SysLog(module = "机构模块", value = "机构更新")
    @ApiOperationSupport(order = 3)
    @Operation(summary = "机构更新")
    @PostMapping(value = "/update")
    public Result<?> update(@Validated @RequestBody DeptUpdateDTO deptUpdateDTO) {
        deptService.updateDept(deptUpdateDTO);
        return Result.ok();
    }

    @SysLog(module = "机构模块", value = "机构删除")
    @ApiOperationSupport(order = 4)
    @Operation(summary = "机构删除")
    @PostMapping(value = "/delete/{id}")
    public Result<?> deleteById(@PathVariable Long id) {
        deptService.removeById(id);
        return Result.ok();
    }

    @SysLog(module = "机构模块", value = "机构排序")
    @ApiOperationSupport(order = 5)
    @Operation(summary = "机构排序")
    @PostMapping(value = "/updateOrder")
    public Result<?> updateOrder(@Validated @RequestBody DeptOrderDTO deptOrderDTO) {
        deptService.OrderDept(deptOrderDTO);
        return Result.ok();
    }


}
